﻿module Lhz.Page.DataManagement {
    class UserManagement extends ManagementPage<Lhz.Entity.ServiceCenter.User> {
        constructor() {
            super({
                targetName: "用户",
                serviceNo: "user",
                colModel: [
                    { title: "用户名", dataIndx: "Username", width: "200", align: "center" },
                    { title: "姓名", dataIndx: "Name", width: "200", align: "center" },
                    { title: "手机", dataIndx: "Phone", width: "200", align: "center" },
                    {
                        title: "管理员", dataIndx: "IsAdmin", width: "200", align: "center", render: function (event, ui) {
                            var item: Lhz.Entity.ServiceCenter.User = event.rowData;
                            return item.IsAdmin === true ? "是" : "否";
                        }
                    }
                ],
                detailPageUrl: "user-detail.html",
                width: 400,
                height: 300,
                getItemName: function (mp, item) {
                    return item.Name;
                },
                initiate: function (mp, callback) {
                    $("#buttonAuthorization").button({ icons: { primary: "ui-icon-key" } }).click(mp, function (event) {
                        var um: UserManagement = event.data;
                        var selections = um.getSelections();
                        if (selections.length == 0) {
                            alert("请选择操作对象。");
                        }
                        else if (selections.length == 1) {
                            var selectedItem = selections[0].item;
                            um.showDialog({
                                url: "user-authorization.html",
                                width: 800,
                                height: 600,
                                title: "授权用户【" + selectedItem.Name + "】",
                                arguments: selectedItem,
                                dialogClosed: function (returnValue: any, um: UserManagement) {
                                    if (returnValue) {
                                        um.query();
                                    }
                                },
                                data: um
                            })
                        }
                        else {
                            alert("该操作暂不支持多选。");
                        }
                    });
                    callback(mp);
                }
            });
        }
    }
    $(function () {
        new UserManagement();
    });
}
